/**
 * 依赖于两个插件一个heatmap.js  一个cesiumheatmap
 */
import CesiumHeatmap  from './CesiumHeatmap'
import gisTools from "../GisTools";
export default new  class heatMap{
    heatMap:any;
    constructor(){
     this.heatMap=null;
    }
    /**
     * 开始渲染
     * @param {*} coords  计算范围
     * @param {*} geojson  渲染热力
     */
    startRender(viewer:any,features:any){
        gisTools.cameraFlyToPoint(viewer,[ 119.56751284, 31.74209036 ],3000);
        const points:any = []
        let west = 1000; let east = -1000; let south = 1000; let north = -1000;
        let valueMin = 0
        let valueMax = 0
        features.forEach(function(feature:any) {
            let lon =null;//经度
            let lat = null;//维度
            if(feature.geometry.type==="point"){
                lon =feature.geometry.coordinates[1];
                lat = feature.geometry.coordinates[1];
            }else if(feature.geometry.type==="MultiPolygon"){
                let center=gisTools.computeCenter(feature);
                let jwd84= gisTools.Cartesian3ToLngLat(center);
                let jwd2000=gisTools.wgs84ToCgcs2000([[jwd84.latitude,jwd84.longitude]]);
                lon =jwd2000[0][1];
                lat =jwd2000[0][0];
            }
            west = Math.min(west, lon)
            east = Math.max(east, lon)
            south = Math.min(south, lat)
            north = Math.max(north, lat)
            let hight=feature.properties.gd;
            if(hight){
                hight=Number(hight)
            }else{
                hight=0
            }
            valueMax=Math.max(valueMax, hight)
            points.push({
                x: lon,
                y: lat,
                value: hight
            })
        })
        const bounds = {
            west,
            east,
            south,
            north
        }
        this.heatMap = CesiumHeatmap.create(
            viewer,
            bounds,
            {
                minOpacity: 0.15,
                maxOpacity: 0.8,
                radius: 50,
                blur: 0.9,
                gradient: {
                    '.2': '#546AA4',
                    '.4': '#0DB212',
                    '.6': '#D6CE3B',
                    '.8': '#CC9C1B',
                    '1': '#DC0F2A'
                }
            }
        )
        this.heatMap.setWGS84Data(valueMin, 10, points)
    }

    //控制显隐
    controlHideOrShow(flag:boolean){
        this.heatMap.show=flag;
    }

    removeCharts(){
        this.heatMap.removeChart()
    }



}
